<template>
  <div class="home">
    <div class="banner">

      <h1 style="margin-top: 1rem">需求标题: {{ ymtitle }}</h1>
    </div>

    <br />

    <!-- <h2># Trend 组件 </h2> -->

    <a-divider> 信息 </a-divider>

    <a-divider> 问题文件列表 </a-divider>

    <a-card style="margin-bottom: 3rem">

      <a-table :columns="columns" :data-source="data">
        <span slot="action" slot-scope="text, record">
          <a @click="seewj(record)">查看文件&nbsp;</a>
          <a @click="xzwj(record)">&nbsp;&nbsp;&nbsp;下载文件</a>
        </span>
      </a-table>

    </a-card>
    <a-divider> 方案文件列表 </a-divider>

    <a-card style="margin-bottom: 3rem">

      <a-table :columns="columnfas" :data-source="fadata">
        <span slot="action" slot-scope="text, record">
          <a @click="seefawj(record)">查看文件&nbsp;</a>
          <a @click="xzfawj(record)">&nbsp;&nbsp;&nbsp;下载文件</a>
        </span>
      </a-table>

    </a-card>
  </div>
</template>

<script>
  // @ is an alias to /src

  import {
    httpAction,
    getAction,
    putAction
  } from '@/api/manage'
  import Trend from '@/components/Trend'
  import AvatarList from '@/components/AvatarList'
  import CountDown from '@/components/CountDown/CountDown'
  import Ellipsis from '@/components/Ellipsis'
  import NumberInfo from '@/components/NumberInfo'

  const AvatarListItem = AvatarList.AvatarItem

  export default {
    name: 'Home',
    components: {
      NumberInfo,
      Ellipsis,
      CountDown,
      Trend,
      AvatarList,
      AvatarListItem
    },
    data() {
      return {
        ymtitle: '',
        value: '1',
        fileList: [],
        columns: [
          {
            title: '问题文件地址',
            dataIndex: 'wtfileguid',
            key: 'wtfileguid'
          },

          {
            title: '文件操作',
            key: 'action',
            scopedSlots: {
              customRender: 'action'
            }
          }
        ],
        columnfas: [

          {
            title: '方案文件地址',
            dataIndex: 'fafileguid',
            key: 'fafileguid'
          },
          {
            title: '文件操作',
            key: 'action',
            scopedSlots: {
              customRender: 'action'
            }
          }
        ],
        targetTime: new Date().getTime() + 3900000,
        url: {
          wjlisturl: '/seefilelist'
        },
        loading: true,
        loadingMore: false,
        showLoadingMore: true,
        data: [],
        fadata: [],

        formLayout: 'horizontal',
        form: this.$form.createForm(this, {
          name: 'coordinated'
        })

      }
    },
    methods: {
      onEndHandle() {
        this.$message.success('CountDown callback!!!')
      },
      onChange(e) {
        console.log('radio checked', e.target.value)
      },
      handleSubmit(e) {
        e.preventDefault()
        this.form.validateFields((err, values) => {
          if (!err) {
            console.log('Received values of form: ', values)
            let fjlx = ''
            if (this.value == '1') {
              fjlx = 'wtfj'
            } else {
              fjlx = 'fafj'
            }
            let params = {
              ids: values.note,
              fjlx: fjlx
            }
            console.log(params)
            getAction(this.url.wjlisturl, params).then((res) => {
              if (res.success) {
                this.data = res.result
                this.$message.success(res.message)
              }
            })
          }
        })
      },
      seefawj(record) {
          let Base64 = require('js-base64').Base64 // base64编码
            var url = 'http://work.hbidding.com/jeecg-boot/sys/common/static/' + record.fafileguid // 要预览文件的访问地址

            window.open('http://work.hbidding.com/preview/onlinePreview?url=' + encodeURIComponent(Base64.encode(url)))
        },

        xzwj(record) {
          window.open('http://work.hbidding.com/jeecg-boot/sys/common/static/' + record.wtfileguid)
        },

        xzfawj(record) {
          window.open('http://work.hbidding.com/jeecg-boot/sys/common/static/' + record.fafileguid)
        },

      // 查看文件操作
      seewj(record) {
        console.log(record)

       // this.fileList = record.wtfileguid.split(',')
        let Base64 = require('js-base64').Base64 // base64编码
       // for (var a = 0; a < this.fileList.length; a++) {
         // console.log('文件列表', this.fileList[a])
          var url = 'http://work.hbidding.com/jeecg-boot/sys/common/static/' + record.wtfileguid // 要预览文件的访问地址

          window.open('http://work.hbidding.com/preview/onlinePreview?url=' + encodeURIComponent(Base64.encode(url)))
       // }
      }

    },
    created() {
      var s = location.href
      console.log(s)
      s = s.substring(s.indexOf('?')).split('&')
      var params
      for (var i = 0; i < s.length; i++) {
        if (s[i].indexOf('id') > -1) {
          var n = s[i].split('=')
          params = n[1]
        }
      }
      console.log(params)
      getAction('/seefilelist/' + params, '').then((res) => {
        if (res.success) {
          this.ymtitle = res.result[0].title
          if (res.result[0].wtfileguid != undefined) {
             var list = res.result[0].wtfileguid
             for (var i = 0; i < list.length; i++) {
                 this.data.push({ wtfileguid: list[i] })
                console.log(this.data)
             }
          }
           if (res.result[1].fafileguid != undefined) {
              var falist = res.result[1].fafileguid
              for (var j = 0; j < falist.length; j++) {
                  this.fadata.push({ fafileguid: falist[j] })
                 console.log(this.fadata)
              }
           }
        }
      })
    }
  }
</script>

<style scoped>
  .home {
    width: 900px;
    margin: 0 auto;
    padding: 25px 0;
  }

  .home>.banner {
    text-align: center;
    padding: 25px 0;
    margin: 25px 0;
  }
</style>
